home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / ms-0_06.lha / bms-0.06 / ms_ipc.h < prev    next >
C/C++ Source or Header  |  1993-08-06  |  3KB  |  116 lines

  1. /* ms_ipc.h - layout of messages passed between Mama and the slave, */
  2. /*            and other network stuff */
  3. /* Copyright (C) 1990, 1991 Andreas Gustafsson */
  4.  
  5. #ifndef _ms_ipc_h
  6. #define _ms_ipc_h
  7.  
  8. #ifndef __TYPES__
  9. /* __TYPES__ is defined by X headers that include <sys/types.h> */
  10. #include <sys/types.h>
  11. #include <sys/file.h>    /* HP-UX needs this for FNDELAY */
  12. #endif
  13.  
  14. #include <fcntl.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17. #include <netdb.h>
  18.  
  19. /* network to host byteorder, long (signed) integer (ntohl may return an */
  20. /* unsigned long) */
  21. #define ntohli(x) ((long) ntohl(x))
  22.  
  23.  
  24. /* update these whenever changes have been made to the layout of */
  25. /* any of the structures defined below */
  26.  
  27. #define VERSION        5    /* major version */
  28. #define DATA_FORMAT     7    /* minor version (name is historical) */
  29.  
  30. /* miscellaneous magic constants */
  31.  
  32. #define MAX_DATAGRAM    8192    /* maximum datagram size */
  33. #define MAGIC         0x9872    /* magic number */
  34. #define DEFAULT_PORT    9359    /* default UDP port */
  35.  
  36. /* message types */
  37.  
  38. #define WHIP_MESSAGE 0
  39. #define REPLY_MESSAGE 1
  40. #define WHO_R_U_MESSAGE 2
  41. #define I_AM_MESSAGE 3
  42.  
  43.  
  44. typedef struct
  45. { unsigned short magic;        /* magic number */
  46.   unsigned short type;        /* packet type */
  47.   unsigned short version;    /* protocol version */
  48.   unsigned short format;     /* data format (= minor protocol version) */
  49. } MessageHeader;
  50.  
  51. typedef struct
  52. { unsigned short pid;        /* process id of requesting process */
  53.   unsigned short seq;        /* sequence number */
  54.   unsigned short chunk_no;    /* chunk number within current sequence */
  55.   unsigned short slave_no;    /* index into the client's slave table */
  56. } MessageId;
  57.  
  58.  
  59. /* C doesn't support zero-sized arrays; it's a shame. */
  60. #ifdef __GNUCC__
  61. #define VARIES 0
  62. #else
  63. #define VARIES 1
  64. #endif
  65.  
  66. /* Work request message */
  67. typedef struct
  68. { MessageHeader header;
  69.   MessageId id;
  70.   char data[VARIES];        /* this really is a ms_job, but pretend */
  71. } WhipMessage;            /* not to know that */
  72.  
  73.  
  74. /* Reply message */
  75. /* the reply message need not contain any corner, delta, or rectangle field */
  76. /* because these are saved in the chunk */
  77. typedef struct
  78. { MessageHeader header;
  79.   MessageId id;
  80.   unsigned long mi_count;
  81.   union
  82.   { unsigned char chars[1];
  83.     unsigned short shorts[1];
  84.   } data;
  85. } ReplyHeader;
  86.  
  87. /* Slave PID inquiry message */
  88. typedef struct
  89. { MessageHeader header;
  90.   unsigned short port;
  91.   unsigned short pad;
  92. } WhoAreYouMessage;
  93.  
  94. /* Reply to PID inquiry */
  95. typedef struct
  96. { MessageHeader header;
  97.   short pid;
  98.   short pad;
  99. } IAmMessage;
  100.  
  101. /* Used when we don't know the message type yet */
  102. typedef struct
  103. { MessageHeader header;
  104. } GenericMessage;
  105.  
  106. typedef union
  107. { char c[MAX_DATAGRAM];
  108.   GenericMessage generic;
  109.   ReplyHeader reply;
  110.   WhipMessage whip;
  111.   WhoAreYouMessage who;
  112.   IAmMessage iam;
  113. } Message;
  114.  
  115. #endif /* _ms_ipc_h */
  116.